package tasks

import (
	"cm2/exception"
	"time"
)

// Downloader 下载更新包
type Downloader struct {
	Task
}

// NewDownloader 创建一个下载更新包任务执行器
func NewDownloader() *Downloader {
	tpkg := &Downloader{}
	tpkg.SId = SIdPrefix("ADB29B21-2F74-4C41-A114-48379CFDDF80")
	tpkg.Code = "Downloader"
	tpkg.Name = "下载器"

	return tpkg
}

// InnerTask 获取SId
func (tpkg *Downloader) InnerTask() *Task {
	return &tpkg.Task
}

// Execute 执行
func (tpkg *Downloader) Execute(task *Task) (interface{}, string, *exception.Exception) {
	// fmt.Println(params)
	// fmt.Printf("执行 Downloader 需要等待 3秒 %s %v", task.Serial, task.Params)
	lock := make(chan bool, 1)
	go func() {
		// fmt.Println("Downloader 调用到咯1")
		time.Sleep(time.Second * 3)
		//fmt.Println("Downloader 调用到咯2")

		lock <- true
	}()
	<-lock
	return "你是谁", "Downloader 调用完成咯", nil
}
